//
//  FristViewController.m
//  Second
//
//  Created by Alex on 16/7/13.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "FristViewController.h"

@interface FristViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong)UICollectionView *collertionView;
// cell上的图片
@property (nonatomic,strong)UIImageView *imageView;
@property (nonatomic,strong)UILabel *name;
@property (nonatomic,strong)UILabel *place;

@end

@implementation FristViewController

- (UICollectionView *)collertionView {
    
    if (!_collertionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        _collertionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight) collectionViewLayout:layout];
        _collertionView.dataSource = self;
        _collertionView.delegate = self;
        layout.itemSize = CGSizeMake(kWidth/2-15, kWidth/2+50);
        layout.sectionInset = UIEdgeInsetsMake(10, 10, 0, 10);
        
    }
    return _collertionView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize target:self action:@selector(rightAction)];
    
    [self.collertionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.collertionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collertionView];
  
    [RequestManager fecthDataWithUrl:@"http://114.215.124.64/api/index.php/goods_list" parameter:@{} mehtod:@"POST" compelet:^(NSData *data) {
       
 //       NSDictionary *bigdic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
  //      NSLog(@"%@",bigdic);
    } updateUI:^{
        
    }];
  
    
}

- (void)rightAction {
    
    XMClassViewController *classVC = [[XMClassViewController alloc]init];
    [self.navigationController pushViewController:classVC animated:YES];
    
    
}

#pragma mark -----------collectionViewDegelate-----------

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor brownColor];
    cell.layer.masksToBounds = YES;
    cell.layer.cornerRadius = 10;
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, kWidth/2-25, kWidth/2)];
    self.imageView.image = [UIImage imageNamed:@"3"];
    self.imageView.layer.masksToBounds = YES;
    self.imageView.layer.cornerRadius = 10;
    self.name = [[UILabel alloc]initWithFrame:CGRectMake(5, kWidth/2+5, kWidth/2-25, 20)];
    self.name.text = @"这是大家的学号，如果有12345";
    self.name.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
    self.place = [[UILabel alloc]initWithFrame:CGRectMake(kWidth/2-80, kWidth/2+25, 60, 20)];
    self.place.textAlignment = NSTextAlignmentRight;
    self.place.textColor = [UIColor redColor];
    self.place.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
    self.place.text = @"$1000.00";
    [cell.contentView addSubview:self.imageView];
    [cell.contentView addSubview:self.name];
    [cell.contentView addSubview:self.place];
    
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    XMSecondController *second = [[XMSecondController alloc]init];
    [self.navigationController pushViewController:second animated:YES];

    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}


@end
